package com.ruoyi.system.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.MyUser;
import com.ruoyi.system.service.IMyUserService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 人员查询Controller
 * 
 * @author ruoyi
 * @date 2021-10-09
 */
@RestController
@RequestMapping("/system/users")
public class MyUserController extends BaseController
{
    @Autowired
    private IMyUserService myUserService;

    /**
     * 查询人员查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:users:list')")
    @GetMapping("/list")
    public TableDataInfo list(MyUser myUser)
    {
        startPage();
        List<MyUser> list = myUserService.selectMyUserList(myUser);
        return getDataTable(list);
    }

    /**
     * 导出人员查询列表
     */
    @PreAuthorize("@ss.hasPermi('system:users:export')")
    @Log(title = "人员查询", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(MyUser myUser)
    {
        List<MyUser> list = myUserService.selectMyUserList(myUser);
        ExcelUtil<MyUser> util = new ExcelUtil<MyUser>(MyUser.class);
        return util.exportExcel(list, "人员查询数据");
    }

    /**
     * 获取人员查询详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:users:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(myUserService.selectMyUserById(id));
    }

    /**
     * 新增人员查询
     */
    @PreAuthorize("@ss.hasPermi('system:users:add')")
    @Log(title = "人员查询", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MyUser myUser)
    {
        return toAjax(myUserService.insertMyUser(myUser));
    }

    /**
     * 修改人员查询
     */
    @PreAuthorize("@ss.hasPermi('system:users:edit')")
    @Log(title = "人员查询", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MyUser myUser)
    {
        return toAjax(myUserService.updateMyUser(myUser));
    }

    /**
     * 删除人员查询
     */
    @PreAuthorize("@ss.hasPermi('system:users:remove')")
    @Log(title = "人员查询", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(myUserService.deleteMyUserByIds(ids));
    }
}
